package com.mysharding.shardingUtils;


import org.apache.shardingsphere.sharding.api.sharding.hint.HintShardingAlgorithm;
import org.apache.shardingsphere.sharding.api.sharding.hint.HintShardingValue;

import java.util.*;

public class HintShardingKeyAlgorithm implements HintShardingAlgorithm {
    @Override
    public Collection<String> doSharding(Collection availableTargetNames, HintShardingValue shardingValue) {
        //这里collection根据我测试的经验它代表的实际节点的集合，hintShardingValue则是分片键
        Collection<String> result = new ArrayList<>();
        String s = shardingValue.getLogicTableName();
        for (Object value : shardingValue.getValues()) {
            Long aLong = Long.valueOf(String.valueOf(value));
            String tablename = s + aLong;
            result.add(tablename);
        }
        return result;
    }

    @Override
    public void init() {

    }

    @Override
    public String getType() {
        return "HINT";
    }
}
